var toolbar=[{
				iconCls: 'icon-add',
				text:'添加',
				handler:toAdd
			},'-',{
				iconCls: 'icon-edit',
				text:'修改',
				handler: updSelected
			},'-',{
				iconCls: 'icon-remove',
				text:'删除',
				handler: delSelected
			},'-',{
				iconCls: 'icon-item',
				text:'查看',
				handler: viewSelected
			}];
function operateFunction(value,row,index){
	var html="<span class='span_a' onclick='javascript:updSelected(\""+row.id+"\");'>修改</span>" +
	" | <span class='span_a' onclick='javascript:delSelected(\""+row.id+"\");'>删除</span>" +
	" | <span class='span_a' onclick='javascript:viewSelected(\""+row.id+"\");'>查看</span>"
	return html;
}

/**
 *查看提示框
 */
function viewAlert(){
	parent.$.messager.alert("提示","请选择一行数据进行查看！","info");
}
/**
 *修改提示框
 */
function updAlert(){
	parent.$.messager.alert("提示","请选择一行数据进行修改！","info");
}
/**
 * 未选择提示框
 */
function unSelectedAlert(){
	parent.$.messager.alert("提示","请先选择数据再进行操作！","info");
}
/**
 * 提示选择一行
 */
function selectedOneAlert(){
	parent.$.messager.alert("提示","请先选择一行数据再进行操作！","info");
}
/**
 *格式化时间类型
 */
function formatDate(value,row,index){
	return new Date(value).format("yyyy-MM-dd hh:mm:ss");
}
/**
 * 格式化描述
 */
function formatDescr(value,row,index){
	if(value==null||value==""){
		return "";
	}else if(value.length>10){
		return "<a id='tip' class='easyui-tooltip' title='"+value+"'>"+value.substring(0,10)+"...</a>";
	}else{
		return value;
	}
}
/**
 * 获取选中的行
 * @returns
 */
function getSelectedRows(){
	var rows=grid.datagrid("getSelections");
	if(rows==null||rows.length<1){
		unSelectedAlert();
		return null;
	}else{
		return rows;
	}
}
/**
 * 获取单个id
 * @param val
 * @returns
 */
function getId(val){
	var id="";
	if(val!=null&&(typeof(val)=="string")){
		id=val;
	}else{
		var rows=getSelectedRows();
		if(rows!=null){
			if(rows.length>1){
				selectedOneAlert();
			}else{
				id=rows[0].id;
			}
		}
	}
	return id;
}

/**
 * 获取id的集合
 * @param val
 * @returns
 */
function getIds(val){
	var ids="";
	if(val!=null&&(typeof(val)=="string")){
		ids=val;
	}else{
		var rows=getSelectedRows();
		if(rows!=null){
			for(var i=0,len=rows.length;i<len;i++){
				ids+=rows[i].id+",";
			}
			ids=ids.substring(0,ids.length-1);
		}
	}
	return ids;
}


/**
 * @param val
 */
function updSelected(val){
	var id=getId(val);
	if(id!=""){
		var dialog =null;
		dialog = parent.my.modalDialog({
			title:"修改",
			height:450,
			width:770,
			resizable:true,
			url:base+master+"/toUpd/"+id,
			buttons:[{
				text : "保存",
				iconCls : "icon-ok",
				handler:function(){
					dialog.find("iframe").get(0).contentWindow.submitForm(dialog,grid,parent.$);
				}
			}, {
				text : "取消",
				iconCls : "icon-cancel",
				handler : function() {
					dialog.dialog("destroy");
				}
			}]
		});
	}
}

/**
 * 查看选中的
 * @param val
 */
function viewSelected(val){
	var id=getId(val);
	if(id!=""){
		var url=base+master+"/view/"+id;
		var dialog =null;
		dialog = parent.my.modalDialog({
			title:"查看",
			height:450,
			width:770,
			resizable:true,
			url:url,
			buttons:[{
				text:"关闭",
				iconCls:"icon-ok",
				handler:function(){
					dialog.dialog("destroy");
				}
			}]
		});
	}
}

/**
 * 删除选中的
 * @param val
 */
function delSelected(val){
	var ids=getIds(val);
	if(ids!=""){
		parent.$.messager.confirm("确认","您确认要删除记录吗？",function(r){
			if(r){
				$.post(base+master+"/del",{ids:ids},function(data){
					if(data==true){
						parent.$.messager.alert("提示","删除成功！","info");
						if(grid!=null&&grid!=undefined){
							try{
								grid.datagrid("reload");
								grid.datagrid("clearSelections");
							}catch(e){
								
							}
							try{
								grid.treegrid("reload");
								grid.treegrid("clearSelections");
							}catch(e){
								
							}
						}
					}else{
						parent.$.messager.alert("提示","删除失败！","error");
					}
				},"json");
			}
		});
	}
}
/**
 * 添加
 */
function toAdd(){
	var dialog=null;
	dialog = parent.my.modalDialog({
		title:"添加",
		height:400,
		width:700,
		resizable:true,
		url:base+master+"/toAdd",
		buttons:[{
			text : "保存",
			iconCls : "icon-ok",
			handler:function(){
				dialog.find("iframe").get(0).contentWindow.submitForm(dialog,grid,parent.$);
			}
		}, {
			text : "取消",
			iconCls : "icon-cancel",
			handler : function() {
				dialog.dialog("destroy");
			}
		}]
	});
}

/**
 * 提交数据进度条(阻止重复提交)
 */
function showProcess(isShow,$pjq) {
	if (!isShow) {
		$pjq.messager.progress('close');
		return;
	}
	$pjq.messager.progress({
		title : '温馨提示',
		msg : '正在提交数据...'
	});
}